package cn.felord.debezium.mina;


import cn.felord.debezium.service.TcpActService;
import org.apache.mina.core.service.IoAcceptor;
import org.apache.mina.filter.codec.ProtocolCodecFilter;
import org.apache.mina.filter.codec.textline.TextLineCodecFactory;
import org.apache.mina.transport.socket.nio.NioSocketAcceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.io.IOException;
import java.net.InetSocketAddress;
import java.nio.charset.Charset;

@Component
public class MinaServer {
    @Autowired
    private TcpActService tcpActService;

    public static boolean isRun = false;
    public void start() throws IOException {
        IoAcceptor acceptor = new NioSocketAcceptor();
//        acceptor.getFilterChain().addLast("logger", new LoggingFilter());
//        acceptor.getFilterChain().addLast("codec", new ProtocolCodecFilter(new TextLineCodecFactory(Charset.forName("UTF-8"))));
        acceptor.setHandler(new TimeServerHandler(tcpActService));
        acceptor.bind(new InetSocketAddress(8009));
        isRun = true;
        System.out.println("mina_server启动:8009");
    }
}

